import mock from './mock'
import sph from './sph'
export const getBanners = () => mock.get('/banners');
export const getFloors = () => mock.get('/floors')
export const getSort = () => mock.get('/sort')
export const getBaseCategoryList = () => sph.get('/api/product/getBaseCategoryList')
export const getGoodsList = options => sph.post('/api/list', options)
export const getDetailInfo = skuId => sph.get(`/api/item/${skuId}`)
export const addCart = ({ skuId, skuNum }) => sph.post(`/api/cart/addToCart/${skuId}/${skuNum}`)
export const getCartList = () => sph.get('/api/cart/cartList')
//修改购物车商品
export const updateCart = ({ skuId, skuNum }) => sph.post(`/api/cart/addToCart/${skuId}/${skuNum}`)
export const delCart = skuId => sph.delete(`/api/cart/deleteCart/${skuId}`)
export const switchChecked = ({ skuId, isChecked }) => sph.get(`/api/cart/checkCart/${skuId}/${isChecked}`)
export const switchAllChecked = (skuIdArr = [], isChecked) => {
    let arr = []
    skuIdArr.forEach((skuId) => {
        const promise = switchChecked({ skuId, isChecked });
        arr.push(promise)
    })
    return Promise.all(arr);
}
//获取验证码
export const getCode = phone => sph.get(`/api/user/passport/sendCode/${phone}`)
//注册,post请求，第二个参数为请求体数据
export const register = ({ phone, password, code }) => sph.post('/api/user/passport/register', { phone, password, code })
//登录验证
export const login = ({ phone, password }) => sph.post('/api/user/passport/login', { phone, password })
//退出登录
export const logout = () => sph.get('/api/user/passport/logout')
//自动登录,不需要带参数，但是请求头中需要携带token
export const autoLogin = () => sph.get('/api/user/passport/auth/getUserInfo')
//获取订单列表
export const getOrders = (page, limit) => sph.get(`/api/order/auth/${page}/${limit}`)
export const getOrderTrade = () => sph.get("/api/order/auth/trade")
//获取订单的收件人地址
export const getUserAddressList = () =>
    sph.get("/api/user/userAddress/auth/findUserAddressList ")
/*提交订单
    trade:{
        consignee:收件人姓名,
        consigneeTel:收件人电话,
        deliveryAddress:收件地址,
        paymentWay:"ONLINE"
        orderComment:订单备注,
        orderDetailList:存储多个商品对象的数组
    }
*/
export const submitOrder = (tradeNo, trade) =>
    sph.post(`/api/order/auth/submitOrder?tradeNo=${tradeNo}`, trade)
/*获取订单支付信息*/
export const getPayInfo = orderId =>
    sph.get(`/api/payment/weixin/createNative/${orderId}`)
/*查询订单的支付状态*/
export const getPayState = orderId => sph.get(`/api/payment/weixin/queryPayStatus/${orderId}`)
